//
//  WeatherAddCollectionViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/16.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "WeatherAddCollectionViewCell.h"
#import "DataAnalysis.h"
@implementation WeatherAddCollectionViewCell
- (void)dealloc
{
    [_lineLabel release];
    [_areaLabel release];
    [_imageV release];
    [_tmpLabel release];
    [_city release];
    [_weather release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
        self.areaLabel = [[UILabel alloc] init];
        self.areaLabel.font = [UIFont systemFontOfSize:20 *kWidth];
        self.areaLabel.textColor = [UIColor whiteColor];
        self.areaLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_areaLabel];
        [_areaLabel release];
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lineLabel];
        [_lineLabel release];
        
        self.tmpLabel = [[UILabel alloc] init];
        self.tmpLabel.textColor = [UIColor whiteColor];
        self.tmpLabel.textAlignment = NSTextAlignmentCenter;
        self.tmpLabel.font = [UIFont systemFontOfSize:50 *kWidth];
        
        [self.contentView addSubview:_tmpLabel];
        [_tmpLabel release];
        
        self.imageV = [[UIImageView alloc] init];
        [self.contentView addSubview:_imageV];
        [_imageV release];
    }
    return self;
}
- (void)setCity:(NSString *)city{

    if (_city != city) {
        [_city release];
        _city = [city retain];
    }
    [self data];

}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.areaLabel.frame = CGRectMake(0, 10 *kHeight, 150*kWidth, 30*kHeight);
    self.lineLabel.frame = CGRectMake(0, 45 *kHeight, 170 *kWidth, 2 *kHeight);
    self.tmpLabel.frame = CGRectMake(10 *kWidth, 45 *kHeight, 110 *kWidth, 100 *kHeight);
    self.imageV.frame = CGRectMake(120 *kWidth, 85 *kHeight, 40 *kWidth , 40 *kHeight);

}
- (void)data{
    
        NSString *urlString = [NSString stringWithFormat:@"http://tq.91.com/api/?act=107&pid=115&word=%@ &osv=8.1&dm=iPhone5,3&chl=otSy9Zonl/k5CTkt33reOQ==&sv=3.13.0&spid=1&nt=10&imei=D3BF9AF1-1DF9-4B08-86CB-F4CB972E3DF0&mt=1",self.city];
    
    NSString *beijingString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

    
    [DataAnalysis dataAnalysisGETWithUrlString:beijingString parameters:nil showHuD:YES hiddenView:nil successfulBlock:^(id responseObject)
     {
         NSDictionary *dic = responseObject;
         NSString *str = [NSString stringWithFormat:@"http://tq.91.com/api/?chl=otSy9Zonl%@&city=%@&spid=1&productid=8032&osv=8.1&imei=D3BF9AF1-1DF9-4B08-86CB-F4CB972E3DF0&cityname=%@&vercode=3.13.0&dm=%@",@"%2Fk5CTkt33reOQ%3D%3D",[[[dic objectForKey:@"items"] firstObject] objectForKey:@"id"],@"%E7%93%A6%E6%88%BF%E5%BA%97",@"iPhone5%2C3&sv=3.13.0&option=now,weather,tqzs,tqyj,sun,pm,wind&act=215&pid=115&chkcode=9c122cd2f020dd001c4e30f00c4218a3&nt=10&mt=1"];
         [DataAnalysis dataAnalysisGETWithUrlString:str parameters:nil showHuD:NO hiddenView:nil successfulBlock:^(id responseObject) {
             NSDictionary *data = responseObject;
             
             self.weather = [WeatherModel weatherWithDictionary:data];
             self.areaLabel.text = self.city;
             self.tmpLabel.text = [NSString stringWithFormat:@"%@°",[self.weather.now objectForKey:@"temp"]];
             NSString *imageName = @"";
             if ([[_weather.now objectForKey:@"nowweather"] containsString:@"阴"]) {
                 imageName = @"weathericon_3阴@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"晴"]){
                 imageName = @"weathericon_1晴日@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"多云"]){
                 
                 imageName = @"weathericon_2多云日@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"霾"]){
                 
                 imageName = @"weathericon_6霾@2x";
                 
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"小雨"]){
                 imageName = @"weathericon_7小雨@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"中雨"]){
                 
                 imageName = @"weathericon_8中雨@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"大雨"]){
                 
                 imageName = @"weathericon_9大雨@2x";
             }else if([[_weather.now objectForKey:@"nowweather"] containsString:@"阵雨"]){
                 imageName = @"weathericon_13阵雨日@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"冰雹"]){
                 
                 imageName = @"weathericon_17冰雹@2x";
                 
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"雷"]){
                 
                 imageName = @"weathericon_15雷电@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"雨夹雪"]){
                 
                 
                 imageName = @"weathericon_18雨夹雪@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"小雪"]){
                 
                 imageName = @"weathericon_19小雪@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"中雪"]){
                 
                 imageName = @"weathericon_20中雪@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"大雪"]){
                 
                 imageName = @"weathericon_21大雪@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"暴雪"]){
                 
                 imageName = @"weathericon_22暴雪@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"阵雪"]){
                 imageName = @"weathericon_23阵雪@2x";
             }
             else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"风"]){
                 
                 imageName = @"weathericon_37大风@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"台风"]){
                 
                 imageName = @"weathericon_38台风@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"龙卷风"]){
                 
                 imageName = @"weathericon_40龙卷风@2x";
             }else if ([[_weather.now objectForKey:@"nowweather"] containsString:@"雾"]){
                 
                 imageName = @"weathericon_4雾@2x";
             }
             
             self.imageV.image = [UIImage imageNamed:imageName];

             
         } failureBlock:^(NSError *error) {
             
         }];
         
     } failureBlock:^(NSError *error) {
         
     }];
}

@end
